﻿using Humanizer;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.Logistics;
using MVC_System.DTO.Supplier;
using MVC_System.DTO.Warehouse;
using NuGet.Packaging.Signing;
using WMS_MAV;
using static System.Net.WebRequestMethods;
namespace MVC_System.Controllers
{
    public class SupplierController : Controller
    {
        private readonly IConfiguration _configuration;
        public SupplierController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        /// <summary>
        /// 供应商列表
        /// </summary>
        /// <returns></returns>
        public IActionResult SupplierShow()
        {
            return View();
        }
        /// <summary>
        /// 供应商显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoSupplierShow(SupplierShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "mhb/api/Supplier/SupplierShow?pageiden=" + dto.pageindex + "&pageSzen=" + dto.pagesize;
            var respomse = await client.GetAsync(url);
         
            return Json(respomse);
        }
        /// <summary>
        /// 供应商添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoSupplierAdd(SupplierShowAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "mhb/api/Supplier/SupplierAdd";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }

        /// <summary>
        /// 供应商删除API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoSupplierDelete(SupplierDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/Supplier/SupplierDelete";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }

        /// <summary>
        /// 供应商反填API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoSupplierFan(SupplierFanDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/Supplier/SupplierFan?supplierID=" + dto.supplierID;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }



        /// <summary>
        /// 添加物流信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoLogisticsAdd(LogisticsInTransitDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/Logistics/LogisticsAdd";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }


        /// <summary>
        /// 查看物资信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoLogisticsFan(LogisticsFanDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "mhb/api/Logistics/LogisticsFan?purchaseNumber=" + dto.purchaseNumber;
            var respomse = await client.GetAsync(url);

            return Json(respomse);
        }

        /// <summary>
        /// 送货
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoLogisticsInTransit(LogisticsInTransitDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/Logistics/LogisticsInTransit";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }

        /// <summary>
        /// 待收货
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoLogisticsSignFor(LogisticsInTransitDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/Logistics/LogisticsSignFor";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }

        /// <summary>
        /// 判断入库信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoStoragesPurchaseNumberShow(StoragesPurchaseNumberShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/Storages/StoragesPurchaseNumberShow?ProcuredNumber=" + dto.ProcuredNumber;
            var respomse = await client.GetAsync(url);

            return Json(respomse);
        }

    }
}
